//
//  FQDetailListCollectionViewCell.swift
//  SwiftProject
//
//  Created by 董駸 on 2023/4/17.
//

import UIKit

class FQDetailListCollectionViewCell: UICollectionViewCell {
    var model : FQDetailListModel! {
        didSet {
            imageV.backgroundColor = .red
            nameLb.text = "曹先生"
            addressLb.setTitle("西安", for: .normal)
            amountLb.text = "放款金额：24100元"
            timeLb.text = "2022.7.26 15:24"
            waitTimeLb.text = "放款等待时间：2小时"
        }
    }
    
    var isLast : Bool = false {
        didSet {
            if isLast {
                contentView.layer.cornerRadius = 8
                contentView.layer.maskedCorners = [.layerMaxXMaxYCorner, .layerMinXMaxYCorner]
            } else {
                contentView.layer.cornerRadius = 0
            }
            lineV.isHidden = isLast
        }
    }

    let imageV = UIImageView()
    let nameLb = QMUILabel(font: .rSFont(14), textColor: .color51)
    let addressLb = QMUIButton(title: "", titleColor: .color153, font: .rSFont(12))
    let amountLb = QMUILabel(font: .mSFont(14), textColor: .color51)
    let timeLb = QMUILabel(font: .rSFont(11), textColor: .color153)
    let waitTimeLb = QMUILabel(font: .rSFont(11), textColor: .color153)
    let lineV = UIView()

    override init(frame: CGRect) {
        super.init(frame: frame)

        contentView.clipsToBounds = true
        contentView.backgroundColor = .white
        
        imageV.contentMode = .scaleAspectFill
        imageV.clipsToBounds = true
        imageV.layer.cornerRadius = 12
        contentView.addSubview(imageV)
        
        imageV.snp.makeConstraints { make in
            make.left.equalTo(24)
            make.top.equalTo(10)
            make.size.equalTo(24)
        }
        
        contentView.addSubview(nameLb)
        nameLb.snp.makeConstraints { make in
            make.left.equalTo(imageV.snp.right).offset(6)
            make.centerY.equalTo(imageV)
        }
        
        addressLb.spacingBetweenImageAndTitle = 2
        addressLb.setImage(UIImage(named: "detail_location"), for: .normal)
        addressLb.isUserInteractionEnabled = false
        addressLb.imagePosition = .left
        contentView.addSubview(addressLb)
        
        addressLb.snp.makeConstraints { make in
            make.left.equalTo(nameLb.snp.right).offset(6)
            make.centerY.equalTo(nameLb)
        }
        
        contentView.addSubview(amountLb)
        amountLb.snp.makeConstraints { make in
            make.right.equalTo(-24)
            make.centerY.equalTo(addressLb)
        }
        
        contentView.addSubview(timeLb)
        timeLb.snp.makeConstraints { make in
            make.left.equalTo(imageV)
            make.bottom.equalTo(-6)
        }
        
        contentView.addSubview(waitTimeLb)
        waitTimeLb.snp.makeConstraints { make in
            make.right.equalTo(amountLb)
            make.centerY.equalTo(timeLb)
        }
        
        lineV.backgroundColor = .color238
        contentView.addSubview(lineV)
        
        lineV.snp.makeConstraints { make in
            make.left.equalTo(24)
            make.right.equalTo(-24)
            make.bottom.equalToSuperview()
            make.height.equalTo(1)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
